const Base = require('../../base.js');

module.exports = class extends Base {
  async indexAction() {
    let data = this.post()
    let userInfo = await this.session('user_info')
    if (!userInfo) return this.fail(-1, '用户未登录')
    // 获取任务详情
    let task_result = await this.model('task_result/index').info(data._id)
    if (!task_result) return this.fail(-1, '还没有领取任务')
    task_result = task_result.result
    /// 判断用户是否是当前用户
    if (task_result.uid != userInfo._id) return this.fail(-1, '用户授权异常')
    /// 判断用户是否可以发起审核
    if (task_result.status != 0) return this.fail(-1, '已经提交审核，请勿重复提交')
    /// 修改数据
    await this.model('task_result/index').finish(data._id, data.text, data.picture)

    this.json({
      status: 200, message: 'success'
    })
  }
};
